<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="奖惩">
        <el-input v-model="name"></el-input>
      </el-form-item>
      <el-form-item label="学生姓名">
        <el-input v-model="stuName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="selectByPage(1,5,name,stuName)">搜索</el-button>
        <router-link to="/manager/addRecord"><el-button>添加</el-button></router-link>
      </el-form-item>
    </el-form>
    <el-table
      :data="pi.list"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="奖惩">
      </el-table-column>
      <el-table-column
        prop="stu.name"
        label="学生姓名">
      </el-table-column>

      <el-table-column
        prop="createBy"
        label="createBy">
      </el-table-column>
      <el-table-column
        prop="createDate"
        label="创建时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <router-link :to="{path:'/manager/updateRecord',query:{id:scope.row.id}}"><el-button>修改</el-button></router-link>
          <el-button @click="deleteRecord(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      layout="sizes, prev, pager, next, jumper, ->, total"
      :total="pi.total"
      :page-size.sync="pi.pageSize"
      :page-sizes="[2,5,10,50]"
      :current-page.sync="pi.pageNum"
      :pager-count="9"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      background>
    </el-pagination>
    <router-view/>
  </div>
</template>

<script>
    export default {
        name: "recordList",
      data(){
          return {
            pi:{},
            name:"",
            stuName:""
          }
      },
      created(){
        //发出ajax请求请求后端代码
        this.selectByPage(1,5,"","");
      },
      methods:{
        handleSizeChange(size){
          //再次调用ajax到后台取数据
          this.selectByPage(this.pi.current,size,this.name,this.stuName);
        },
        handleCurrentChange(page){
          this.selectByPage(page,this.pi.size,this.name,this.stuName);
        },
        selectByPage(pageNum,pageSize,name,stuName){
          this.axios.get("/record/selectByPage", {
              params:{
                pageNo:pageNum,
                pageSize:pageSize,
                name:name,
                stuName:stuName
              }
            }).then((resp)=>{
            this.pi=resp.data;
          });
        },
        deleteRecord(id){
          this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            //发出ajax请求。
            this.axios.delete("/record/delete/"+id).then(()=>{
              //重新查询数据。
              this.selectByPage(this.pi.pageNum,this.pi.pageSize,this.name,this.stuName);
            })
            //提示删除成功！
            this.$message.success("删除成功！")
          });
        }
      }
    }
</script>

<style scoped>

</style>
